package com.dianping.cat.home.group.transform;

import com.dianping.cat.home.group.IEntity;
import com.dianping.cat.home.group.IVisitor;
import com.dianping.cat.home.group.entity.Domain;
import com.dianping.cat.home.group.entity.DomainGroup;
import com.dianping.cat.home.group.entity.Group;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  13 */   private Stack<Object> m_objs = new Stack();

  private DomainGroup m_domainGroup;


  public DefaultMerger() {}

  public DefaultMerger(DomainGroup domainGroup) {
/*  21 */     this.m_domainGroup = domainGroup;
/*  22 */     this.m_objs.push(domainGroup);
  }


/*  26 */   public DomainGroup getDomainGroup() { return this.m_domainGroup; }



/*  30 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  34 */     this.m_objs.push(to);
/*  35 */     from.accept(this);
    this.m_objs.pop();
  }


/*  40 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  44 */   protected void mergeDomainGroup(DomainGroup to, DomainGroup from) { to.mergeAttributes(from); }


  protected void mergeGroup(Group to, Group from) {
/*  48 */     to.mergeAttributes(from);
/*  49 */     to.getIps().addAll(from.getIps());
  }


  public void visitDomain(Domain from) {
/*  54 */     Domain to = (Domain)this.m_objs.peek();

/*  56 */     mergeDomain(to, from);
/*  57 */     visitDomainChildren(to, from);
  }

  protected void visitDomainChildren(Domain to, Domain from) {
/*  61 */     for (Group source : from.getGroups().values()) {
/*  62 */       Group target = to.findGroup(source.getId());

/*  64 */       if (target == null) {
/*  65 */         target = new Group(source.getId());
/*  66 */         to.addGroup(target);
      }

/*  69 */       this.m_objs.push(target);
/*  70 */       source.accept(this);
/*  71 */       this.m_objs.pop();
    }
  }


  public void visitDomainGroup(DomainGroup from) {
/*  77 */     DomainGroup to = (DomainGroup)this.m_objs.peek();

/*  79 */     mergeDomainGroup(to, from);
/*  80 */     visitDomainGroupChildren(to, from);
  }

  protected void visitDomainGroupChildren(DomainGroup to, DomainGroup from) {
/*  84 */     for (Domain source : from.getDomains().values()) {
/*  85 */       Domain target = to.findDomain(source.getId());

/*  87 */       if (target == null) {
/*  88 */         target = new Domain(source.getId());
/*  89 */         to.addDomain(target);
      }

/*  92 */       this.m_objs.push(target);
/*  93 */       source.accept(this);
/*  94 */       this.m_objs.pop();
    }
  }


  public void visitGroup(Group from) {
/* 100 */     Group to = (Group)this.m_objs.peek();

/* 102 */     mergeGroup(to, from);
/* 103 */     visitGroupChildren(to, from);
  }

  protected void visitGroupChildren(Group to, Group from) {}
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/group/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */